home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / pdselect / awnp / awnp-docs / guimod.doc < prev    next >
Text File  |  2000-02-16  |  8KB  |  122 lines

  1.  Before reading this section take a moment and run tutorial 3, knowing what the GUI does will help in understanding the code behind it.
  2.  
  3. This tutorial has two versions, Arexx and 'C'. The 'C' tutorial is after the Arexx one.
  4.  
  5. TUTORIAL 3 AREXX
  6. ---------------
  7.  
  8.  This tutorial deals with modifying a GUI after it has been opened. You should make sure you understand tutorial 2 before reading further.
  9.  
  10.  Three new gadgets have added to the gui. The load and save gadgets on the lower left, and a get file gadget that you do not see. The getfile gadget is unattached (ua) so it is not displayed in the gui. More on the getfile gadget later.
  11.  
  12.  The window definition line (in buildGUI:) has the modify option added to it. This means the pipe will look for modify commands after you fist open the window, and after each event is sent. Any number of modify commands can be written to the pipe, including 0 (none). After writing the modify commands 'continue' must be sent to the pipe to tell it to start sending events. After you get an event the pipe starts waiting for modify commands again.
  13.  
  14.  Only two changes are made in the program flow.
  15.  
  16. 1.  After BUILDGUI is called to build and open the window we send a modify command to the pipe.
  17.  
  18. topipe('id 'savegad' dis 1 ref')
  19.  
  20.  The id specifies the save gadget, 'dis 1' disables it, and 'ref' refreshes it so the changes will show. (we want the save gadget disabled because the name gadget is empty at start up, and we need a name before we can save).
  21.  
  22. 2. In the mail loop a 'continue' is written to the pipe BEFORE we wait for an event. This tells to pipe to stop looking for modify commands and send an event.
  23.  
  24.  After an event is read from the pipe it automatically starts looking for more modify events. This means that modify commands can be used immediately after receiving an event from the pipe.
  25.  
  26.  RESETFORM
  27.  
  28.  In tutorial 2 we had to close then open the GUI to reset its contents. With modify commands we can do this with the gui remaining open. The function resetform is near the end of tutorial3.rx.
  29.  
  30.  This function sends a modify command for each of the gadgets resetting them to the default values. It also disables the save gadget.
  31.  
  32.  SAVEFORM
  33.  
  34.  This function is called when the user hits the save gadget. It writes the forms contents to a file in 't:'. The files name is the text from the name gadget with '.formdemo' appended to it. The save gadget is disabled unless the name gadget contains text. See the handling of namegad in the GADGET: routine.
  35.  
  36.  LOADFORM
  37.  
  38.  This function makes use of the unattached GETFILE gadget. A modify command is used to set the file name in the file requester, and to open the requester itself. The pattern used in the file requester was set when the gadget was created in the BUILDGUI routine.
  39.  
  40. call writeln(ca,'id 'getfilegad' fn "t:" s 1')
  41.  
  42. 'fn "t:"' sets the file requester to the drawer T:. 's 1' opens the requester.
  43.  
  44.  The return from the pipe to this modify command is read and parsed to get the file selected and to test if the user selected a file or aborted the requester. The reply from the pipe is ...
  45.  
  46. SUCCESS ["filename"]
  47.  
  48.  Success is 0 if the user aborts the file requester, non zero if a file is selected. The file name is always returned in quotes since multiple files can be selected in some situations. (but not this situation).
  49.  
  50.  If the user selected a file, it is opened and the contents placed in the GUI. No error checking is done on the file in order to keep the tutorial clear and easy to understand.
  51.  
  52. TUTORIAL 3 in C
  53. ---------------
  54.  
  55.  This tutorial deals with modifying a GUI after it has been opened. You should make sure you understand tutorial 2 before reading further.
  56.  
  57.   int buildgui(struct GUIpipe * GP);
  58.  
  59. The window definition line (in buildgui()) has the modify option added to it. This means the pipe will look for modify commands after you fist open the window, and after each event is sent. Any number of modify commands can be written to the pipe, including 0 (none). After writing the modify commands 'continue' must be sent to the pipe to tell it to send an event. After you get an event the pipe starts waiting for modify commands again.
  60.  
  61.  Three new gadgets have added to the gui. The load and save gadgets on the lower left, and a get file gadget that you do not see. The getfile gadget is unattached (ua) so it is not displayed in the gui. More on the getfile gadget later.
  62.  
  63.  int main( int argc, char *argv[]);
  64.  
  65.  Only two changes are made in the program flow.
  66.  
  67. 1.  After buildgui() is called to build and open the window we send a modify command to the pipe.
  68.  
  69.      topipe(GP,"id %ld dis 1 ref\n",savegad);
  70.  
  71.  The id specifies the save gadget, 'dis 1' disables it, and 'ref' refreshes it so the changes will show. (we want the save gadget disabled because the name gadget is empty at start up, and we need a name before we can save).
  72.  
  73. 2. In the main loop a 'continue' is written to the pipe BEFORE we wait for an event. This tells to pipe to stop looking for modify commands and send an event.
  74.  
  75.  After an event is read from the pipe it automatically starts looking for more modify events. This means that modify commands can be used immediately after receiving an event from the pipe.
  76.  
  77.  int gadgets(struct GUIpipe * GP);
  78.  
  79.  The 'loadgad' and 'savegad' gadgets are recognised, and the handling of 'namegad' and 'resetgad' have changed.
  80.  
  81.  In tutorial 2 we had to close then open the GUI to reset its contents. With modify commands we can do this with the gui remaining open. We set our default form information and call updategui().
  82.  
  83.  Namegad enables or disables the savegad. If no name is set we can not generate a filename to save the information to.
  84.  
  85. int updategui(struct GUIpipe * GP);
  86.  
  87.  This routine updates the GUI to show the values we have stored internaly. A modify line is sent for each gadget. The function updateform is near the end of tutorial3.rx.
  88.  
  89.  int saveform(VOID);
  90.  
  91.  This function is called when the user hits the save gadget. It writes the forms contents to a file in 't:'. The files name is the text from the name gadget with '.formdemo' appended to it. The save gadget is disabled unless the name gadget contains text. See the handling of namegad in the gadget() routine.
  92.  
  93.  int loadform(struct GUIpipe * GP);
  94.  
  95.  This function makes use of the unattached GETFILE gadget. A modify command is used to set the file name in the file requester, and to open the requester itself. The pattern used in the file requester was set when the gadget was created in the BUILDGUI routine.
  96.  
  97.    FPrintf(GP->file,"id %ld fn \"t:\" s 1\n",getfilegad);
  98.    if (getevent(GP)) return(1);
  99.  
  100.  
  101. 'fn "t:"' sets the file requester to the drawer T:. 's 1' opens the requester.
  102.  
  103.  The return from the pipe to this modify command is read and parsed as an event since it does not return the usual 'ok'. The reply from the pipe is ...
  104.  
  105. SUCCESS ["filename"]
  106.  
  107.  Success is 0 if the user aborts the file requester, non zero if a file is selected. The file name is always returned in quotes since multiple files can be selected in some situations. (but not this situation).
  108.  
  109.  If the user selected a file, it is opened and the contents parsed into out internal form information. Then updategui() is called.. No error checking is done on the file in order to keep the tutorial clear and easy to follow.
  110.  
  111.  
  112.  __stdargs int topipe(struct GUIpipe * GP, UBYTE * data,...);
  113.  int getline(struct GUIpipe * GP);
  114.  int gperror(struct GUIpipe * GP,int error);
  115.  int getevent(struct GUIpipe * GP);
  116.  int menu(struct GUIpipe * GP);
  117.  UBYTE * eventstr(struct GUIpipe * GP, int num);
  118.  VOID setdefaults(VOID);
  119.  
  120.  These routines have not been changed from Tutorial 2.
  121.  
  122.